package com.sumainfor.pc.market.controller.Feign;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.service.Feign.PactService;
import com.sumainfor.pc.market.service.RdPactService;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/6/17 19:36
 * @Description:
 */
@RestController
@RequestMapping("/key/pact")
@Log4j2
public class PactController {

    @Autowired
    PactService PactService;

    /**
     * 功能描述:
     * 获取所有的合同列表
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/17 19:37
     */
    @GetMapping("/getAllPactList")
    public List<Map<String, Object>> getAllPactList() {
        return PactService.getAllPactList();
    }

    /**
     * 功能描述:
     * 根据合同编号获取合同资料
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/7/3 5:26
     */
    @GetMapping("/getPactByPaIdMap")
    public JsonResult getPactByPaIdMap(@RequestParam Map<String, Object> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"PaId"})) {
            return JsonResult.error("PaId不能为空！");
        }
        return JsonResult.success(PactService.getPactByPaIdMap(params));
    }

    /**
     * 功能描述:
     * 根据租客编号和合同编号获取租客合同资料
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/7/11 20:45
     */
    @GetMapping("/getPcatInfoByPaIdAndTenIdMap")
    public Map<String, Object> getPcatInfoByPaIdAndTenIdMap(@RequestParam Map<String, Object> params) {
        log.info("params-------", params);
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"PaId"})) {
            return JsonResult.error("PaId不能为空！");
        }
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"TenId"})) {
            return JsonResult.error("TenId不能为空！");
        }
        return PactService.getPcatInfoByPaIdAndTenIdMap(params);
    }


    /**
     * 获取合同的pdf文件url路径 通过合同的编号进行查询
     *
     * @param patId
     * @return
     */
    @RequestMapping("/getPactPDFLink")
    public JsonResult getPactPDFLink(String patId) {
        if (StringUtils.isBlank(patId)) {
            return JsonResult.errorForEmpty();
        }
        return PactService.getPactPDFLink(patId);
    }
}
